package democompare;

public class Test {
    public static void main(String[] args) {
        System.out.println("使用comparable");
        Student s1 = new Student("zhangsan", 12);
        Student s2 = new Student("lisi", 21);
        if(s1.compareTo(s2) > 0) {
            System.out.println("student1 > student2");
        } else if(s1.compareTo(s2) == 0) {
            System.out.println("student1 == student2");
        } else {
            System.out.println("student1 < studetn2");
        }

        System.out.println("使用Age_comparator");
        AgeComparator agecomparator = new AgeComparator();//实例化AgeComparator类
        int ret = agecomparator.compare(s1, s2);
        if(ret > 0) {
            System.out.println("Student1 > Student2");
        } else {
            System.out.println("Student1 <= Student2");
        }

        System.out.println("使用Name_comparator");
        NameComparator namecomparator = new NameComparator();//实例化NameComparator类
        ret = namecomparator.compare(s1, s2);
        if(ret > 0) {
            System.out.println("Student1 > Student2");
        } else {
            System.out.println("Student1 <= Student2");
        }

    }
}
